package com.se.lang;

import javax.sql.DataSource;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.http.HttpClient;
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import jdk.internal.loader.*;

/**
 * @Author: hdu_huang
 * @Date: 2020/11/30 9:22
 */
public class ModuleTest {

    public static void main(String[] args) throws Exception{

        //ClassLoader.nameToModule/classes
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader platformClassLoader = ClassLoader.getPlatformClassLoader();
        ClassLoader bootstrap = platformClassLoader.getParent(); //BuiltinClassLoader  ClassLoaders

        Module unnamedModule = platformClassLoader.getUnnamedModule();
        Set<String> packages1 = unnamedModule.getPackages();

        Class<ModuleTest> moduleTestClass = ModuleTest.class;
        Module module = moduleTestClass.getModule();
        Set<String> packages = module.getPackages();

        //platformClassLoader:java.sql  java.net.http  java.script[javax]...
        //platformClassLoader有能力加载java开头的类
        ClassLoader classLoader1 = HttpClient.class.getClassLoader();
        ClassLoader classLoader2 = Statement.class.getClassLoader();
        ClassLoader classLoader3 = DataSource.class.getClassLoader();

        Module module1 = HttpClient.class.getModule();

        Field parent = BuiltinClassLoader.class.getDeclaredField("parent");
        parent.setAccessible(true);
        ClassLoader bootClassLoader  = (ClassLoader) parent.get(platformClassLoader);
        Class<?> aClass = BootLoader.loadClassOrNull("com.se.lang.AutoClosedTest"); //null

        //bootstrapClassLoader -Xbootclasspath/a   unsafe.defineClass
        String bootstrapClassPath = System.getProperty("jdk.boot.class.path.append");
        //{Java_home}\jre\lib\ext  or java.ext.dirs
        String property = System.getProperty("java.ext.dirs");
        System.out.println(property);
        String appClassPath = System.getProperty("java.class.path");
        System.out.println();


        System.out.println(module);
    }
}
